//
//  DestinationSecTableViewCell.m
//  EDPS
//
//  Created by Neil on 15/11/25.
//  Copyright © 2015年 张维扬. All rights reserved.
//

#import "DestinationSecTableViewCell.h"
#import "DestinationSecButtonCollectionCell.h"
#import "UIImageView+WebCache.h"
#import "hottest_places.h"

@interface DestinationSecTableViewCell ()<UICollectionViewDataSource ,UICollectionViewDelegate >

@property (nonatomic, retain)  UICollectionView *collectionView;
//@property (nonatomic, retain)  hottest_places *hostPlaces;

@end

@implementation DestinationSecTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self creatCollectionView];
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
}
- (void)setPhotoArr:(NSMutableArray *)photoArr
{
   /* hottest_places *hostPlace = [_photoArr objectAtIndex:0];
    NSLog(@"_photoArr.cover = %@",hostPlace.cover);
    NSLog(@"_photoArr.content = %@",hostPlace.comments_count);*/
    _photoArr = photoArr;
   // NSLog(@"_photoArr = %@",_photoArr);
    [self.collectionView reloadData];
}
#pragma mark - 创建collectionView

- (void)creatCollectionView
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(ScreenWidth / 2 - 20, 150);
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight / 2 + 200) collectionViewLayout:layout];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.collectionView registerClass:[DestinationSecButtonCollectionCell class] forCellWithReuseIdentifier:@"collectionCell"];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView.showsVerticalScrollIndicator = NO;
    [self.contentView addSubview:self.collectionView];
    
}
#pragma mark - collectionView协议方法
#pragma mark - cell内容
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    DestinationSecButtonCollectionCell *collectionCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionCell" forIndexPath:indexPath];
   
    hottest_places *hostPlace = [_photoArr objectAtIndex:indexPath.row];
    
    NSString *photoUrl = hostPlace.cover;
    [collectionCell.postImageView sd_setImageWithURL:[NSURL URLWithString:photoUrl]];
    collectionCell.titleLable.text = hostPlace.name;
    NSString *contentText = hostPlace.comments_count;
   // [hostDic objectForKey:@"comments_count"];
    collectionCell.commentLable.text = [NSString stringWithFormat:@"%@点评", contentText];
    collectionCell.backgroundColor = [UIColor purpleColor];
    return collectionCell;
}

#pragma mark - 点击方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [collectionView deselectItemAtIndexPath:indexPath animated:YES];
    [self.delegate pasIndexPath:indexPath.row];
}

#pragma mark - cell个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _photoArr.count;
}



@end